package com.cellulam.framework.core.model;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * 分页对象
 *
 * @param <E>
 */
@Getter
@Setter
public class PagerResponse<E> {
    public PagerResponse() {
    }

    /**
     * 总数
     */
    private Long total;

    /**
     * 下一页是否有数据
     */
    private Boolean hasMore;

    private int pageSize;

    public int getPageCount() {
        if(this.total == null || this.total <= 0 || this.pageSize <= 0) {
            return 0;
        }
        return (int) ((this.total - 1) / this.pageSize + 1);
    }

    /**
     * 数据
     */
    private List<E> data;

    public Boolean getHasMore() {
        if (hasMore == null) {
            return this.total == null ? false : total > 0;
        }

        return this.hasMore;
    }


    public static final PagerResponse EMPTY;

    static {
        EMPTY = new PagerResponse<>();
        EMPTY.setData(null);
        EMPTY.setHasMore(false);
        EMPTY.setTotal(0L);
    }

    public static final <T> PagerResponse<T> empty() {
        return (PagerResponse<T>) EMPTY;
    }
}
